﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Modelling.Components;
using ITAP.ShprossesBuilder.Properties;

namespace ITAP.ShprossesBuilder.Operations
{
    public class OperationRemoveComponent : IOperation
    {
        #region IOperation Members

        public string Name
        {
            get { return "Удалить компоненты"; }
        }

        public OperationGroup OperationGroup
        {
            get { return OperationGroup.Other; }
        }

        public System.Drawing.Image Thumbnail
        {
            get { return Resources.DeleteHS; }
        }

        public void Execute(ModelControl modelControl)
        {
            List<IComponent> componentsToRemove = new List<IComponent>();
            foreach (IComponent selectedComponent in modelControl.ModelContainer.SelectedComponentsStack)
            {
                if (selectedComponent is Shpross || selectedComponent is ShprossConnector || selectedComponent is SnapOnCap)
                {
                    IComponent parent = selectedComponent.Parent;
                    parent.RemoveInnerComponent(selectedComponent);
                    componentsToRemove.Add(selectedComponent);
                }
            }

            foreach (IComponent componentToRemove in componentsToRemove)
            {
                modelControl.ModelContainer.SelectedComponentsStack.Remove(componentToRemove);
            }
        }

        #endregion

        #region IOperation Members


        public bool CanUndo
        {
            get { return true; }
        }

        #endregion
    }
}
